<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html  xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>产品配置</title>
	<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
	<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
	<script type="text/javascript">
	var startP = 1;
	var covContent = "";
	var mainContent = "";
	
	$(document).ready(function() {
		loadCreditProductData();
	});
	function bindradio(){
		$("input[type='radio']").click(function(){
			$("input[name='radioProduct']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");

       	});
	}
	function queryCreditProduct(displayPage){
		var tradProdCode= $("#tradProdCode").val();
		var tradProdDesc= $("#tradProdDesc").val();
		var status= $("#status").val();
		var startDate= $("#startDate").val();
		var endDate= $("#endDate").val();
		loadCreditProductData({current:displayPage,size:10,prodCode:tradProdCode,prodName:tradProdDesc,status:status,startDate:startDate,endDate:endDate});
	}
	var exportflag=false;
	function loadCreditProductData(param){
		   var jsonDate;
			if(null != param && null != param.current){
				var str = "";
				var strReg = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
				var startDate = param.startDate;
				var endDate = param.endDate;
				if(null != startDate && "" != startDate){
					if(startDate.match(strReg)==null){
						$.message("error", "您输入的定义起期格式不正确，格式为:YYYY-MM-DD");
						return;
					}
				}
				if(null != endDate && "" != endDate){
					if(endDate.match(strReg)==null){
						$.message("error", "您输入的定义止期格式不正确，格式为:YYYY-MM-DD");
						return;
					}
				}
				jsonDate =param;
				
			}else{
				jsonDate={current:1,size:10};
			}
			$.openLoading();
			$.ajax({
					url : "creditProduct/queryProdList",
					type : 'POST',
					async : true,
					dataType:'json',
					data:jsonDate,//传递的是 jsonDate = param , 初始化是一个含分页信息的json对象,页面加载完成后通过填写页面的input,能够添加其他信息.
					success : function(page) {//成功传递json后执行
					$.closeLoading();
							if($.validate(page))return;//当页面加载返回 fail或 error,直接返回
							startP = page.current;
							//alert(startP);
							var firstbutton='';
							var flag=page.obj 
							if(flag){
								firstbutton ="<input class='input_fxk' name='radioProduct' type='radio' value='#'>@<input class='input_fxk' name='checkProduct' type='checkBox' value='#'>";
								/* 创建按钮窗体 radio + checkBox */
							}else{
								firstbutton ="<input class='input_fxk' name='radioProduct' type='radio' value='#'>";
							}
							var lastbutton = "<a href='javascript:void(0)' onClick='editTradProdInst(this);return false'>编辑</a>&nbsp<a href='javascript:void(0)' onClick='delTradProdInst(this);return false'>删除</a>";
								/* 创建操作窗体 */
							var tableContent = creatTable5("prodType,prodCode,prodName,prodDesc@TDH,insertTime,isPool@TDH,status?[{0:'无效'};{1:'有效'}],maxDelayDay@TDH,maxDays@TDH,minDays@TDH,agentType@TDH,pppUnit@TDH,maxCancelDay@TDH,minDelayDay@TDH",page,firstbutton,lastbutton);
								/* 创建整体窗体 , 填充DIV */
							var tableObj = $("#gatewayproductTable");
							tableObj.find("tbody").remove();
							tableObj.append(tableContent);
							var strPage = creatChannelPage(startP,6,page.maxPage,"82");
							var pageDIV = $("#txproductpageDIV");
							pageDIV[0].innerHTML="";
							pageDIV.append(strPage);
							bindradio();
							//是否有导出产品功能判断
							exportflag=flag;
							if(flag){
								$("#implBtn").show();
							}else{
								//没有导出权限
								$("#implBtn").hide();
								if($('#gatewayproductTable tr th:eq(1)').html()=="导出"){
									$('#gatewayproductTable tr th:eq(1)').remove();
								}
							}
					}
				});
		}
	function delTradProdInst(obj){
		$.dialog({
			type: "warn",//success,error
			content: "您确定要删除该产品吗？",
			onOk: function() {
				var editTr = $(obj).parent('td').parent('tr')[0];
				var flag=2;
				if(exportflag){
					flag=3;
				}
				var tradProdCode = editTr.childNodes[flag].innerHTML;
				deleteTradProdInst(tradProdCode);
			}
		});
	}
	function deleteTradProdInst(tradProdCode){
		$.openLoading();
		$.ajax({
			url : "creditProduct/deProdInfo?"+new Date().getTime(),
			type : 'POST',
			data:{
				prodCode:tradProdCode
			},
			success : function(obj) {
				$.closeLoading();
				if($.validate(obj))return;
				loadCreditProductData(1);
			}
		});
	}
	var prodCode="";
	var prodType="";
	var originalIsPools = "";
	function editTradProdInst(obj){
 		var editTr = $(obj).parent('td').parent('tr')[0];
 		prodTypeFlag=1;
 		prodCodeFlag=2;
 		prodNameFlag=3;
 		prodDescFlag=4;
 		isPoolFlag=6;
 		statusFlag=7;
 		maxDelayDayFlag=8;
 		maxDaysFlag=9;
 		minDaysFlag=10;
 		agentTypeFlag=11;
 		pppUnitFlag=12;
 		minDelayDayFlag=14;
 		maxCancelDayFlag=13;
	if(exportflag){
		prodTypeFlag=2;
 		prodCodeFlag=3;
 		prodNameFlag=4;
 		prodDescFlag=5;
 		isPoolFlag=7;
 		statusFlag=8;
 		maxDelayDayFlag=9;
 		maxDaysFlag=10;
 		minDaysFlag=11;
 		agentTypeFlag=12;
 		pppUnitFlag=13;
 		minDelayDayFlag=15;
 		maxCancelDayFlag=14;
		}
 		prodType = editTr.childNodes[prodTypeFlag].innerHTML;
 		prodCode = editTr.childNodes[prodCodeFlag].innerHTML;
 		var prodName = editTr.childNodes[prodNameFlag].innerHTML;
 		var prodDesc = editTr.childNodes[prodDescFlag].innerHTML;
 		var isPool = editTr.childNodes[isPoolFlag].innerHTML;
 		//originalIsPools = isPool;
 		var status = editTr.childNodes[statusFlag].innerHTML;
 		var maxDelayDay = editTr.childNodes[maxDelayDayFlag].innerHTML;
 		var maxDays = editTr.childNodes[maxDaysFlag].innerHTML;
 		var minDays = editTr.childNodes[minDaysFlag].innerHTML;
 	 	/* var agentType = editTr.childNodes[agentTypeFlag].innerHTML;  */
 		var pppUnit = editTr.childNodes[pppUnitFlag].innerHTML;
 		var minDelayDay =editTr.childNodes[minDelayDayFlag].innerHTML;
 		var maxCancelDay=editTr.childNodes[maxCancelDayFlag].innerHTML;
 		$("#eprodCode").val(prodCode);
		$("#eprodType").val(prodType);
 		$("#eprodName").val(prodName);
 		$("#eisPool").val(isPool);
 		//$("#conInsuCode").val(conInsuCode);
 		//hidenOrShowConInsuType();
 		$("#eprodDesc").val(prodDesc);
 		if("" == minDelayDay){
 			$("#minDelayDay").val(0);
 		}else{
 			$("#minDelayDay").val(minDelayDay);
 		}
 		if("" == maxDelayDay){
 			$("#maxDelayDay").val(0);
 		}else{
 			$("#maxDelayDay").val(maxDelayDay);
 		}
 		if("" == maxCancelDay){
 			$("#maxCancelDay").val(0);
 		}else{
 			$("#maxCancelDay").val(maxCancelDay);
 		}
 		$("#maxDays").val(maxDays);
 		$("#minDays").val(minDays);
 		$("#PPP_UNIT").find("option[value='"+pppUnit+"']").attr("selected",true);
 		/* $("#agentType").val(agentType); */
		if(status=='有效')
		{
	 		$("#estatus").val('1');
		}
		if(status=='无效')
		{
	 		$("#estatus").val('0');
		}
 		$("#editProdDiv").OpenDiv();
	}

	function vreset(){
		$("#tradProdCode").val("");
		$("#tradProdDesc").val("");
		$("#startDate").val("");
		$("#endDate").val("");
		$("#status").val("");
	}
	function add(){
		window.location.href='<%=basePath%>creditProduct/addReq';
	}
	
	
	function closeEditProdDiv(){
		$("#editProdDiv").CloseDiv();
		originalIsPools = "";
	}
	function exProduct(){
		var tradProdCode='';
		$("input[name='checkProduct']:checked").each(function(){
			if(''==tradProdCode){
				 tradProdCode = $(this).parent().parent().children("td:eq(3)").html()
			}else{
				 tradProdCode =tradProdCode+","+ $(this).parent().parent().children("td:eq(3)").html()
			}
		});
		if(tradProdCode==''){
			$.message("error", "请至少选择一个产品");
			return;
		}
		window.location.href='<%=basePath%>creditProduct/dowloadProd?productCode='+tradProdCode;
	}
	function saveEditProd(){
		$.openLoading();
		 if($.trim($("#eprodName").val()).length==0){
		    	$.message("error","产品名称不能为空");
		    	$prodName.focus();
		    	return false;
		    }
		    //产品归类
		    if($("#eprodType").val()==""){
		    	$.message("error","请选择产品归类");
		    	$prodType.focus();
		    	return false;
		    }
		 
		  //产品状态
		    if($("#estatus").val()==""){
		    	$.message("error","请选择产品状态");
		    	$status.focus();
		    	return false;
		    }
		   /* 
		    //共保选项
		    if($("#eisPool").val()==""){
		    	$.message("error","请选择共保类型");
		    	$isPool.focus();
		    	return false;
		    }
		   //最长延时起保天数：不小于0的整数，且首位非0
		    if($.trim($("#maxDelayDay").val()).length==0){
		    	 $.message("error","请输入最长延时起保天数");
		    	$maxDelayDay.focus();
		    	return false; 
		    }else{
		    	var maxDelayDayReg = new RegExp("^(0|[1-9][0-9]*)$");
				var delayflag = maxDelayDayReg.test($("#maxDelayDay").val());
				if(!delayflag){
					$.message("error","最长延时起保天数必须是不小于0的整数");
					$maxDelayDay.focus();
					return false;
				}
				if(parseInt($("#minDelayDay").val())>parseInt($("#maxDelayDay").val())){
					$.message("error","最长延时起保天数不能小于最短延时起保天数");
					$maxDelayDay.focus();
					return false;
				}
			}
		  	//最短保险天数：大于等于1的正整数
		    if($.trim($("#minDays").val()).length==0){
		    	 $.message("error","请输入最短保险天数");
		    	$minDays.focus();
		    	return false;
		    }else{
				var minDayReg = new RegExp("^[1-9][0-9]*$");
				var minDayflag = minDayReg.test($("#minDays").val());
				if(!minDayflag){
					$.message("error","最小保险期间必须是不小于1的整数");
					$minDays.focus();
					return false;
				}
			}
		  	//最长注销天数:只能填入大于等于0的整数，默认为0.
		    if($.trim($("#maxCancelDay").val()).length=0){
		    	 $.message("error","请输入最长注销天数");
		    	$("#maxCancelDay").focus();
		    	return false; 
		    }else{
		    	//alert($longestCancelDay.val());
		    	var minDelayDayReg = new RegExp("^(0|[1-9][0-9]*)$");
		        var delayflag = minDelayDayReg.test($("#maxCancelDay").val());
		        if(!delayflag){
		        	$.message("error","最长注销天数必须是不小于0的整数")
		        	$("#maxCancelDay").focus();
		        	return false;
		        }
		    }

		 	//最短延时起保天数：不小于0的整数，且首位非0
		    if($.trim($("#minDelayDay").val()).length==0){
		    	$.message("error","请输入最短延时起保天数");
		    	$("#minDelayDay").focus();
		    	return false;
		    }else{
		    	var minDelayDayReg = new RegExp("^(0|[1-9][0-9]*|-[1-9][0-9]*)$");
				var delayflag = minDelayDayReg.test($("#minDelayDay").val());
				if(!delayflag){
					$.message("error","最短延时起保天数必须是整数");
					$("#minDelayDay").focus();
					return false;
				}
			}
		  	
		  	//最长保险天数：大于等于1的正整数，且必须大于最短保险天数
		    if($.trim($("#maxDays").val()).length==0){
		    	 $.message("error","请输入最长保险天数");
		    	$maxDays.focus();
		    	return false;
		    }else{
				var maxDayReg = new RegExp("^[1-9][0-9]*$");
				var maxDayflag = maxDayReg.test($("#maxDays").val());
					if(!maxDayflag){
					if($maxDays.val()!=0){
						$.message("error","最大保险期间必须是不小于1的整数");
						$("#maxDays").focus();
						return false;
					}
				}
				if(parseInt($("#minDays").val())>parseInt($("#maxDays").val())){
					$.message("error","最大保险期间不能小于最小保险期间");
					$maxDays.focus();
					return false;
				}
			} */
		
		$.ajax({
			url:"creditProduct/updateCreditProd?"+new Date().getTime(),
			type:'POST',
			data:{
				prodCode:$("#eprodCode").val(),
				prodName:$("#eprodName").val(),
				status:$("#estatus").val(),
				/* isPool:$("#eisPool").val(),
				maxDelayDay:$("#maxDelayDay").val(),
				minDelayDay:$("#minDelayDay").val(),
				maxCancelDay:$("#maxCancelDay").val(),
				minDays:$("#minDays").val(),
				maxDays:$("#maxDays").val(),
				pppUnit:$("#pppUnit").val(), */
				prodDesc:$("#eprodDesc").val()
				},
			success:function(obj){
				$.closeLoading();
				if($.validate(obj))return;
				loadCreditProductData(1);
			}
		})
	}
	</script>
</head>
<body >
	<div class="current">
           <table class="current_table_1">
              <tbody>
                <tr class="f2">
                  <td>
                    <img src="./images/current_1.jpg">
                  </td>
                  <td class="current_table_1_td">
                    <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                      <span style=" color:#136bab; ">信保产品管理
                      <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>产品配置
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody>
         </table>
      </div>
		
		<table class="table_02" id="table">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td width="20%" height="30">产品代码：
								<input name="txt3" id="tradProdCode" type="text" class="input_text" maxlength="30" value="">
							</td>
							<td width="20%" height="30">产品名称：
								<input name="txt3" id="tradProdDesc" type="text" class="input_text" maxlength="100" value="">
							</td>
							<td width="20%" height="30">状态：
							 	<select class="search_select_1" id="status">
									<option value="">--请选择--</option>
									<option value="1">有效</option>
									<option value="0">无效</option>
								</select>
							</td>
							<td width="20%" height="30">定义起期：
								<input id="startDate" onkeydown="false" onclick="showCalendar('startDate','y-mm-dd');" readonly="readonly" class="input_time" type="text" />
							</td>
							<td width="20%" height="30">定义止期：
								 <input id="endDate" onkeydown="false" onclick="showCalendar('endDate','y-mm-dd');" readonly="readonly" class="input_time" type="text" />
							</td>
						</tr>
						<tr height="30px">
							<td style="text-align: center;" colspan="5" width="100%" height="30">
								<input type="button" class="input_button_1" id="searchBtn" value="查询" onClick="queryCreditProduct(1)" />&nbsp;
							    <input type="button" class="input_button_1" id="searchBtn" value="重置" onClick="vreset()" />
							</td>
						</tr> 
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td width="100%" height="30">
								<input type="button" class="input_button_2" id="searchBtn" value="新增产品" onClick="add()" />&nbsp;
								<input type="button" class="input_button_2" id="implBtn" value="产品导出" onClick="exProduct()" style="display: none;"/>
								<!-- <input type="button" class="input_button_2" id="searchBtn" value="配置险别" onClick="insuranceAdd()"/>&nbsp;
								<input type="button" class="input_button_2" id="searchBtn" value="共保配置" onClick="conInsureAdd()"/>
								<input type="button" class="input_button_2" id="detailBtn" value="详情" onClick="showDetailByRadio()"> -->
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="gatewayproductTable" class="content_table_1">
						<thead>
							<tr class="f1">
								<th style="width:10%;">选择</th>
								<th style="width:5%;" >导出</th>
								<th style="width:15%;">产品归类</th>
								<th style="width:15%;">产品代码</th>
								<th style="width:25%;">产品名称</th>
								<th style="width:15%;">定义时间</th>
								<th style="width:5%;">状态</th>
								<th style="width:10%;">操作</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="txproductpageDIV" class="page"></div>
				</td>
			</tr>
		</table>
		
		<!--   	添加模板 DIV 默认隐藏-->
	    <div id="editProdDiv"  style="display:none;overflow-y:auto; width:60%">
			<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="/manager/images/closedown.gif" alt="关闭"  onclick="closeEditProdDiv()"/></td>
						</tr>
					</table>
			</div>
			<!-- 修改id 名 -->
			<table class="table_02" id="addtempletTable" align="center">
				<tbody>
					<tr>
						<td>
							<table id="coverageTable"  class="content_table_1" style="height:120px;">
								<tbody>
									<tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">产品代码：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eprodCode" class="input_text" disabled='disabled' style="width: 250px"><span class="red">*</span></td>
					                </tr>
									<tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">产品名称：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eprodName" class="input_text" style="width: 250px"><span class="red">*</span></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">产品归类：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eprodType" class="input_text" disabled='disabled' style="width: 250px;"><span class="red">*</span></td>
					                </tr>
 					               <!--  <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">是否共保：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><select name="eisPool" id="eisPool" class="select_1" style="visibility: visible;width: 250px;" onchange="hidenOrShowConInsuType()">
 	                  				  <option value="N">否</option>
 	                  				  <option value="Y">是</option>
	                  				  </select></td>
					                </tr> -->
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">产品状态：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><select name="estatus" id="estatus" class="select_1" style="visibility: visible;width: 250px;">
 					                  <option value="0">无效</option>
	                  				  <option value="1">有效</option>
					                  </select></td>
					                </tr>
					               <%--  <tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">最长延时起保天数：</td>
					                  <td width="60%" style="text-align:left"><input name="maxDelayDay" id="maxDelayDay" type="text" maxlength="50"  class="input_text" style="width: 250px"></td>
					                </tr>
					                <tr>
					                	<td width="40%" style="text-align:right;border-right:0px;">最短延时起保天数：</td>
						                <td width="60%" style="text-align:left"><input name="minDelayDay"  id="minDelayDay" value="0" type="text" class="input_text" maxlength="5" ><span class="blue">支持负数</span></td>
					                </tr>
					                 <tr>
						              	  <td width="40%" style="text-align:right;border-right:0px;">最长起保后注销天数：</td>
						                  <td width="60%" style="text-align:left"><input name="maxCancelDay"  id="maxCancelDay" value="0" class="input_text" type="text" maxlength="5" value="0"></td>
						              </tr>
					                <tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">保险期间：</td>
					                  <td  width="60%" style="text-align:left">
					                  	<input name="minDays" id="minDays" type="text" maxlength="50"  class="input_text" style="width:60px;">&nbsp;至&nbsp;
					                  	<input name="maxDays" id="maxDays" type="text" maxlength="50"  class="input_text" style="width:60px;">&nbsp;&nbsp;
					                  	<select name="pppUnit" id="pppUnit" class="select_1"  style="width:55px;visibility: visible;">
					                  			<option value=''>--------请选择--------</option>
									            <option value='d'>天</option>
									            <option value='m'>月</option>
									            <option value='y'>年</option>
					                  	</select>
					                  </td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">销售类型：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left">
						                  <select name="agentType" id="agentType" class="select_1" disabled="disabled" style="visibility: visible;width: 250px;">
		 					                  <option value="">--------请选择--------</option>
						                  	  <c:forEach var ="agentType" items="${agentTypeList}">
					                  			 <option value="${agentType.code}">${agentType.codeName}</option>
					                  		  </c:forEach>
						                  </select><span class="red">*</span>
					                  </td>
					                </tr> --%>
					                <!-- <tr class = "isSupportConInsu">
									    <td width='40%' style='text-align:right;border-right:0px;'>共保方式：&nbsp;&nbsp;</td>
									    <td width='60%' style='text-align:left'>
									        <select name='conInsuCode' id='conInsuCode' class='select_1' style='visibility: visible;width: 250px;'>
									            <option value=''>--------请选择--------</option>
									            <option value='01'>共出</option>
									            <option value='02'>共入</option>
									        </select><span class='red'>*</span>
									    </td>
									</tr> -->
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">交易系统产品描述：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><textarea id="eprodDesc"  maxlength="50"  rows="5" class="textarea_1" style="resize:none;width: 250px"></textarea></td>
					                </tr>
								</tbody>
							</table>
							
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center">
			   <input class="input_button_3" name="" type="button" onclick="saveEditProd()" value="保存">&nbsp;&nbsp;
	           <input class="input_button_3" name="" type="button" onclick="closeEditProdDiv()" value="取消">
			</div>
	</div>
		
		<div id="Loading" style="display:none" align="center">
			<img src="./images/loading.gif" />
		</div>
		
		<div id="detail" style="display: none;">
			<div id="input" style="margin: 5px;h word-wrap: break-word"></div>
		</div>
		<div id="detail2" style="display: none;">
			<h4 style="background-color: #A4BDE3;"></h4>
			<table>
				<thead></thead>
				<tr>
					<td width="200px"></td>
					<td align="right"><img src="./images/closedown.gif"
						onclick="closeDiv()" /></td>
				</tr>
			</table>

			<div id="output" style="margin: 5px; word-wrap: break-word"></div>
		</div>
</body>
</html>